#include <bits/stdc++.h>

using namespace std;

class Solution
{
public:
    int minNumberOfHours(int initialEnergy, int initialExperience,
                         vector<int> energy, vector<int> experience)
    {
        int ret = 0;
        for (int i = 0; i < energy.size(); ++i)
        {
            if (initialEnergy <= energy[i])
            {
                ret += energy[i] - initialEnergy + 1;
                initialEnergy = energy[i] + 1;
            }
            if (initialExperience <= experience[i])
            {
                ret += experience[i] - initialExperience + 1;
                initialExperience = experience[i] + 1;
            }
            initialEnergy -= energy[i];
            initialExperience += experience[i];
        }
        return ret;
    }
};
